package org.brisling.service.duties;

import java.util.List;

import org.brisling.base.domain.ListDomain;
import org.brisling.common.ConstSysParam;
import org.brisling.common.util.JsonUtil;
import org.brisling.common.util.LongUtil;
import org.brisling.duties.domain.MediumEquipment;
import org.brisling.duties.repository.LeaveRepo;
import org.brisling.service.base.duties.BaseDutiesListByDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;




@RestController

/**
 * 小型设备采购统计模块后台服務service,
 * @Author : jackson wang
 * @Date   : 2015年6月8日 下午4:18:01
 * @Update : 2015年10月4日 下午12:43:00
 * @version: 1.0
 */
public class SmallEquipmentService extends BaseDutiesListByDeptService<MediumEquipment>{
	
		
	@SuppressWarnings("unused")
	@Autowired
	private LeaveRepo baseRepo;		

	
	public SmallEquipmentService(){
		this.moduleName = ConstSysParam.MODULE_SMALLEQUIPMENT;;
	}
	
	/**
	 * 获取业务主页面 
	 * @return
	 */
	@RequestMapping("/smallEquipmentMainPage.action")
	public ModelAndView getMainPage(){
		return this.getBizMainPage();
	}
	
	/**
	 * 获取业务编辑页面
	 * @return
	 */
	@RequestMapping("/smallEquipmentEditPage.action")
	public ModelAndView getEditPage(){
		return this.getBizEditPage();
	}
	
	
	/**
	 * 分页查询用户列表页面
	 * @param deptid
	 * @param page
	 * @param rows
	 * @param sort
	 * @return
	 */
	@RequestMapping("/smallEquipmentListDomain.action")
	public ListDomain<MediumEquipment> getPagedListDomain(@RequestParam(value="deptid",required=false) String deptid,
			@RequestParam(value="page",required=false) String page,
			@RequestParam(value="rows",required=false) String rows,
			@RequestParam(value="sort",required=false) String sort){
		
		Integer _deptid = LongUtil.getIntValue(deptid, null);		
		ListDomain<MediumEquipment> listDomain = null;
		
		if(_deptid!=null){
			listDomain = super.getPagedListDomainByDeptid(_deptid, page, rows);
		}else{
			listDomain = super.getAllListDomain(page,rows,getSort(sort));
		}
		return listDomain;
	}
	
	/**
	 * 分页查询用户列表页面
	 * @param deptid
	 * @param page
	 * @param rows
	 * @param sort
	 * @return
	 */
	@RequestMapping("/smallEquipmentList.action")
	public List<MediumEquipment> getPagedList(@RequestParam(value="deptid",required=false) String deptid,
			@RequestParam(value="page",required=false) String page,
			@RequestParam(value="rows",required=false) String rows,
			@RequestParam(value="sort",required=false) String sort){
		
		Integer _deptid = LongUtil.getIntValue(deptid, null);		
		List<MediumEquipment> list = null;
		if(_deptid!=null){
			list= super.getPagedListByDeptid(_deptid, page, rows,sort);
		}else{
			list = super.getAll(page,rows,getSort(sort));
		}
		return list;
	}
	
	/**
	 * 删除人员信息
	 * @param id
	 */
	@RequestMapping("/smallEquipmentDel.action")
	public String delSmallEquipment(@RequestParam(value="id",required=false) Long id){
		super.del(id);
		return "200";
	}
	
	
	/**
	 *  保存用户信息
	 * @param body	json 格式数据对象
	 * @return	Users 保存后的对象
	 */
	@RequestMapping("/smallEquipmentSave.action")
	public MediumEquipment save(@RequestBody String body){
		MediumEquipment smallEqu = JsonUtil.bodyToObj(body, MediumEquipment.class);		
		return this.save(smallEqu);
	}	
	
}
